Skip to content

Conversation

@Kludex
Copy link
Owner

@Kludex Kludex commented Oct 9, 2025



class Request(HTTPConnection):
class Request(HTTPConnection[StateT]):
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are missing the same in WebSockets.

strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just so the pipeline can pass, but we shouldn't merge this here.

@Kludex
Copy link
Owner Author

Kludex commented Oct 9, 2025

@alex-oleshkevich @abersheeran Can you check this, please?

@alex-oleshkevich
Copy link
Contributor

@alex-oleshkevich @abersheeran Can you check this, please?

All good.

@Kludex
Copy link
Owner Author

Kludex commented Oct 9, 2025

@alex-oleshkevich @abersheeran Can you check this, please?

All good.

In the sense that this implementation makes sense, or something different? 🤔

@alex-oleshkevich
Copy link
Contributor

@alex-oleshkevich @abersheeran Can you check this, please?

All good.

In the sense that this implementation makes sense, or something different? 🤔

We want to have a typed request state and keep backward compatibility. That was achieved, so all is good :)

@patrick91
Copy link

This was exactly what I had in mind :D thanks @Kludex!



class HTTPConnection(Mapping[str, Any]):
StateT = TypeVar("StateT", bound=Mapping[str, Any] | State, default=State)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this will pass the TypedDict check in some static type checkers.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which one you don't think it will not? We test with mypy here, but pyright doesn't seem to be failing (I use it on my environment).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's great to be able to pass the inspection.

@PerumallaGiridhar
Copy link
Contributor

Hi there! 👋
I’ve added tests to help increase coverage around typed request.state in #3049.
This is my first contribution to Starlette (and to open source in general)
I’d love to keep contributing in this area to help unblock and accelerate improvements.

Copy link
Contributor

@adriangb adriangb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some tests? Some example usage in docstrings? Updated docs that show what users can achieve now, why the new patterns are better, etc.?

Kludex and others added 3 commits January 11, 2026 14:08
Co-authored-by: PerumallaGiridhar <145003734+PerumallaGiridhar@users.noreply.github.com>
@Kludex
Copy link
Owner Author

Kludex commented Jan 11, 2026

Can you add some tests? Some example usage in docstrings? Updated docs that show what users can achieve now, why the new patterns are better, etc.?

I've added documentation, and tests, but I believe most of background for this is in the issue that motivated this PR: #3005

@Kludex Kludex enabled auto-merge (squash) January 18, 2026 09:49
@Kludex Kludex merged commit d8c7cf9 into main Jan 18, 2026
6 checks passed
@Kludex Kludex deleted the state-mapping branch January 18, 2026 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make request.state generic

7 participants